<%@ page contentType="text/javascript; charset=UTF-8"  pageEncoding="UTF-8"%>
<jsp:useBean id="def" class="dbexp.utils.Default" scope="session"/>
Ext.BLANK_IMAGE_URL = 'js/ext/resources/images/default/s.gif';
var formPanel = new Ext.form.FormPanel({
	labelWidth : 75,	
	height : 300,
	frame : false,
	boder:false,
	bodyStyle:'padding:10px',
	items : [{
		title : "Właściwości połączenia",
		xtype : "fieldset",
		layout : "form",
		autoWidth : true,
		autoHeight : true,
		defaults: {
			xtype : 'textfield',
			allowBlank : false,
			width : 100,
			selectOnFocus:true,
			listeners:{
				specialkey:function(field, ev){
					if(ev.getKey() == ev.ENTER){
						var next = field.nextSibling();
						if(next){
							next.focus();
						}else if(field.getName()=='port'){
							formPanel.find('name','name')[0].focus();
						}
			        }
				}
			}
		},
		items :[
		        		{
		        			name : "sid",
		        			value : "<%=def.getDbName()%>",
		        			fieldLabel : "Nazwa bazy"
		        		},{
		        			name:'host',
		        			value : "<%=def.getHostName()%>",
		        			fieldLabel : "Host"
		        		},{
		        			minValue : 0,
		        			allowNegative : false,
		        			fieldLabel : "Port",
		        			xtype : "numberfield",
		        			name : "port",
		        			value : "<%=def.getPort()%>",
		        			allowDecimals : false,
		        			maxValue : 65535
		        		}
		]
	}, {
		title : "Właściwości logowania",
		xtype : "fieldset",
		layout : "form",
		autoWidth : true,
		defaults: {
			xtype : 'textfield',
			allowBlank : false,
			width : 100,
			selectOnFocus:true,
			listeners:{
				specialkey:function(field, ev){
					if(ev.getKey() == ev.ENTER){
						var next = field.nextSibling();
						if(next && !next.hidden){
							next.focus();
						}else if(field.getName()=='password'){
							formPanel.getForm().submit(	{
								method:"POST",
								url: 'login/session.jsp',
								waitTitle:'Laczenie',
		                        waitMsg:'Trwa laczenie z serwerem: '+formPanel.getForm().getValues().host,
								success:function(form, action){
									obj = Ext.util.JSON.decode(action.response.responseText);
									LoginHide().execute(obj.data);
								},
								failure:function(form, action){
									if(action.failureType == 'server'){
										obj = Ext.util.JSON.decode(action.response.responseText);
										Ext.Msg.alert('Logowanie nie powiodło się!', obj.error);
									}else{
										obj = Ext.util.JSON.decode(action.response.responseText);
										Ext.Msg.alert('Blad!', 'Nie można połączyć z serwerem :<b><font color=red> ' + obj.error.msg +'</font></b>');
									}
									formPanel.getForm().reset();
								}
							});
						}
			        }
				}
			}
		},
		items : [
		         		{
		         			name:'name',
		         			value : "SYSTEM",
		         			fieldLabel : "Login"
		         		},{
		         			name:'password',
		         			value : "qazxsw",
		         			fieldLabel : "Hasło",
		         			inputType:'password'
		         		},{
		         			name:'action',
		         			value : "login",
		         			fieldLabel : "",
		         			inputType:'hidden',
		         			hidden:true
		         		}
					],
		autoHeight : true
	}],
	width : 340,
	xtype : "form",
	layout : "form",
	autoWidth : true,
	autoHeight : true,
	border : false,
	forceLayout:true
});

var LoginPanel = new Ext.Window({
			width : 240,
			constrain:true,
			cls:'x-window-draggable',
			buttons : [{
				text : "Zaloguj",
				handler : function() {
				formPanel.getForm().submit(	{
						method:"POST",
						url: 'login/session.jsp',
						waitTitle:'Laczenie',
                        waitMsg:'Trwa laczenie z serwerem: '+formPanel.getForm().getValues().host,
						success:function(form, action){
							obj = Ext.util.JSON.decode(action.response.responseText);
							LoginHide().execute(obj.data);
						},
						failure:function(form, action){
							if(action.failureType == 'server'){
								obj = Ext.util.JSON.decode(action.response.responseText);
								Ext.Msg.alert('Logowanie nie powiodło się!', obj.error);
							}else{
								obj = Ext.util.JSON.decode(action.response.responseText);
								Ext.Msg.alert('Blad!', 'Nie można połączyć z serwerem :<b><font color=red> ' + obj.error.msg +'</font></b>');
							}
							formPanel.getForm().reset();
						}
					});
				}
		}],
			title : "DbExplorer 1.0",
			height : 300,
			closable : false,
			items : [formPanel],
			xtype : "window",
			resizable : false,
			buttonAlign : "center",
			border : true,
			plain : true,
			modal : false,
			draggable : true,
			id:'win'
		});
